package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.DictRelevanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.CityDictionary;
import com.ruoyi.system.service.ICityDictionaryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 字典关联城市Controller
 *
 * @author MagicCube
 * @date 2023-06-09
 */
@RestController
@RequestMapping("/dictionary")
public class CityDictionaryController extends BaseController
{
    @Autowired
    private ICityDictionaryService cityDictionaryService;

    /**
     * 查询字典关联城市列表
     */
    @RequiresPermissions("system:dictionary:list")
    @GetMapping("/list")
    public TableDataInfo list(CityDictionary cityDictionary)
    {
        startPage();
        List<CityDictionary> list = cityDictionaryService.selectCityDictionaryList(cityDictionary);
        return getDataTable(list);
    }
    /**
     * 查询字典关联城市列表
     */
    @GetMapping("/relevanceList")
    public TableDataInfo relevanceList(DictRelevanceVo dictRelevanceVo)
    {
        startPage();
        List<DictRelevanceVo> list = cityDictionaryService.selectCityDictRelevanceList(dictRelevanceVo);
        return getDataTable(list);
    }

    /**
     * 导出字典关联城市列表
     */
    @RequiresPermissions("system:dictionary:export")
    @Log(title = "字典关联城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityDictionary cityDictionary)
    {
        List<CityDictionary> list = cityDictionaryService.selectCityDictionaryList(cityDictionary);
        ExcelUtil<CityDictionary> util = new ExcelUtil<CityDictionary>(CityDictionary.class);
        util.exportExcel(response, list, "字典关联城市数据");
    }

    /**
     * 获取字典关联城市详细信息
     */
    @RequiresPermissions("system:dictionary:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cityDictionaryService.selectCityDictionaryById(id));
    }

    @RequiresPermissions("system:dictionary:query")
    @GetMapping(value = "/dictCityInfo")
    public AjaxResult dictCityInfo(DictRelevanceVo dictRelevanceVo)
    {
        return success(cityDictionaryService.selectDictCityInfo(dictRelevanceVo));
    }

    /**
     * 新增字典关联城市
     */
    @RequiresPermissions("system:dictionary:add")
    @Log(title = "字典关联城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DictRelevanceVo dictRelevanceVo)
    {
        return toAjax(cityDictionaryService.insertCityDict(dictRelevanceVo));
    }

    /**
     * 修改字典关联城市
     */
    @RequiresPermissions("system:dictionary:edit")
    @Log(title = "字典关联城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DictRelevanceVo dictRelevanceVo)
    {
        return toAjax(cityDictionaryService.updateCityDict(dictRelevanceVo));
    }

    /**
     * 删除字典关联城市
     */
    @RequiresPermissions("system:dictionary:remove")
    @Log(title = "字典关联城市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cityDictionaryService.deleteCityDictionaryByIds(ids));
    }
}
